{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：1. None\n",
    "答案：2. [30,4]\n",
    "答案：3. 3\n",
    "答案：4. 97"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：1. ×\n",
    "答案：2. × （元组可以作为字典的键，列表永远不能作为字典的键）\n",
    "答案：3. ×\n",
    "答案：4. ×"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'lys'\n",
      "Counter({\"'\": 2, 'l': 1, 'y': 1, 's': 1})\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "text = input('请输入一个字符串：')\n",
    "frequencies = Counter(text)\n",
    "print(frequencies)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'lys'\n",
      "[('l', 1), ('y', 2), ('s', 3)]\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')\n",
    "positions = [(ch,index) for index,ch in enumerate(text) if text.index(ch) == text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入字符内容：'liliyushi'\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "x = input('请输入字符内容：')\n",
    "d = {}\n",
    "for i in x:\n",
    "    d[i] = d.get(i, 0) + 1\n",
    "for j in d:\n",
    "    if d[j] == 1:\n",
    "        print(x.index(j))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个列表：[{1,2,3,4,5,6,7,8,9},{5,9,7}]\n",
      "{1, 2, 3, 4, 5, 6, 7, 8, 9}\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "lstA = eval(input(\"请输入一个列表：\"));\n",
    "print(reduce(lambda x, y:x | y, lstA));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'liyushi'\n",
      "NO\n"
     ]
    }
   ],
   "source": [
    "str1 = input('请输入一个字符串')\n",
    "str2 = str1[::-1]\n",
    "if str1 == str2:\n",
    "    print('YES')\n",
    "else:\n",
    "    print('NO')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：1. 可迭代对象\n",
    "答案：2. 4\n",
    "答案：3. None\n",
    "答案：4. remove()\n",
    "答案：5. [6,7,9,11]\n",
    "答案：6. {}；键；值；键\n",
    "答案：7. items();key();values()\n",
    "答案：8. ['dict(zip(a,b))']\n",
    "答案：9. b = a[::3]\n",
    "答案：10. 5 for i in range(10)\n",
    "答案：11. 不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['liyushi', 'liyuyushi']\n"
     ]
    }
   ],
   "source": [
    "#答案：12.\n",
    "data = ['liyushi','liliyuyushishi','liyuyushi']\n",
    "print(list(filter(lambda s:len(set(s))/len(s) >0.5,data)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "#答案：13.\n",
    "def lys(x):\n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output = filter(lys,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：14. 当列表从中间或从头增加或删除元素时，列表对象自动进行内存扩展或收缩，从而保证元素之间没有缝隙，但这涉及到列表元素的大量的移动，效率较低，应尽量从列表尾部进行元素的增加与删除操作以提高处理速度."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[77, 36, 29, 20, 0, 86, 91, 32, 59, 32, 19, 53, 0, 99, 21, 94, 2, 53, 10, 92, 42, 8, 25, 26, 75, 69, 13, 60, 64, 25, 45, 19, 14, 58, 74, 23, 35, 28, 10, 83, 46, 83, 27, 8, 14, 14, 83, 48, 7, 4, 56, 73, 67, 89, 90, 3, 74, 63, 93, 87, 29, 2, 25, 26, 16, 96, 23, 9, 7, 60, 44, 4, 26, 1, 23, 51, 54, 97, 34, 96, 31, 77, 79, 10, 91, 96, 16, 57, 76, 11, 55, 17, 49, 74, 16, 32, 22, 66, 30, 60, 5, 91, 65, 21, 65, 35, 13, 54, 35, 66, 40, 97, 62, 8, 52, 51, 18, 1, 75, 61, 63, 53, 41, 66, 14, 43, 74, 87, 100, 84, 83, 33, 13, 58, 39, 14, 40, 35, 18, 56, 42, 71, 73, 13, 33, 56, 41, 9, 76, 44, 40, 86, 22, 8, 79, 40, 18, 26, 72, 14, 77, 71, 58, 67, 27, 17, 98, 17, 40, 14, 49, 71, 36, 19, 8, 77, 35, 17, 25, 46, 4, 47, 59, 82, 33, 5, 21, 20, 84, 5, 2, 58, 34, 21, 49, 45, 42, 12, 58, 54, 50, 76, 38, 0, 76, 5, 91, 42, 98, 9, 5, 55, 91, 99, 92, 62, 78, 66, 27, 79, 13, 63, 77, 5, 40, 25, 89, 21, 56, 5, 11, 68, 26, 14, 95, 100, 35, 83, 90, 3, 52, 53, 21, 94, 57, 14, 96, 20, 23, 20, 47, 49, 63, 87, 89, 88, 15, 59, 93, 94, 5, 70, 51, 93, 58, 90, 56, 81, 100, 65, 26, 81, 58, 90, 46, 17, 77, 47, 74, 1, 24, 36, 79, 50, 30, 92, 56, 27, 73, 17, 71, 41, 57, 21, 26, 43, 18, 30, 12, 19, 70, 74, 32, 82, 53, 37, 98, 45, 10, 67, 57, 95, 2, 89, 74, 61, 86, 73, 70, 35, 33, 1, 98, 25, 8, 83, 39, 37, 63, 43, 92, 10, 89, 88, 22, 56, 58, 32, 99, 49, 70, 26, 61, 4, 22, 53, 64, 25, 47, 62, 84, 90, 94, 88, 66, 35, 24, 3, 6, 57, 52, 77, 80, 14, 50, 66, 16, 54, 13, 19, 74, 80, 75, 12, 93, 5, 4, 20, 8, 98, 47, 47, 43, 87, 27, 10, 46, 67, 14, 39, 0, 78, 60, 80, 69, 95, 17, 26, 94, 93, 100, 51, 76, 33, 99, 44, 8, 85, 83, 15, 37, 80, 65, 25, 98, 22, 32, 60, 61, 51, 8, 55, 57, 32, 93, 53, 28, 73, 29, 22, 91, 74, 100, 44, 49, 25, 97, 48, 32, 32, 64, 82, 76, 85, 65, 27, 88, 30, 50, 98, 22, 19, 95, 23, 52, 45, 73, 86, 43, 1, 93, 64, 100, 19, 23, 22, 13, 32, 51, 51, 89, 21, 73, 8, 50, 26, 70, 16, 57, 98, 0, 96, 93, 81, 51, 49, 33, 3, 70, 88, 58, 93, 54, 29, 72, 15, 26, 72, 40, 85, 6, 34, 50, 97, 79, 61, 46, 62, 29, 96, 47, 66, 46, 60, 60, 75, 76, 39, 2, 71, 26, 86, 3, 57, 9, 92, 100, 82, 66, 86, 52, 32, 10, 47, 11, 69, 28, 94, 70, 61, 82, 29, 44, 8, 38, 94, 28, 61, 12, 29, 10, 33, 71, 81, 86, 84, 95, 1, 60, 81, 61, 97, 17, 20, 47, 78, 46, 76, 85, 94, 69, 18, 46, 23, 31, 79, 46, 24, 40, 2, 60, 77, 56, 66, 25, 3, 13, 70, 36, 59, 8, 26, 81, 73, 23, 95, 4, 46, 35, 23, 71, 71, 47, 53, 14, 3, 5, 45, 93, 50, 48, 96, 85, 37, 63, 40, 54, 96, 36, 16, 94, 67, 72, 92, 52, 89, 19, 86, 41, 10, 73, 65, 65, 13, 26, 29, 20, 74, 17, 1, 79, 45, 19, 49, 19, 1, 49, 28, 31, 71, 83, 37, 87, 41, 61, 61, 70, 77, 28, 90, 53, 87, 44, 45, 84, 26, 13, 27, 23, 82, 36, 25, 59, 44, 85, 15, 42, 55, 88, 28, 92, 10, 1, 91, 56, 94, 84, 75, 24, 71, 87, 35, 78, 27, 68, 31, 65, 31, 85, 48, 3, 44, 100, 12, 74, 83, 64, 29, 33, 25, 28, 38, 84, 49, 61, 66, 4, 1, 75, 4, 52, 59, 21, 31, 95, 69, 89, 12, 78, 7, 77, 0, 16, 98, 36, 70, 67, 89, 42, 92, 14, 12, 84, 5, 91, 16, 52, 100, 62, 92, 13, 32, 35, 39, 2, 25, 30, 7, 90, 0, 99, 61, 53, 38, 77, 54, 47, 48, 93, 69, 17, 21, 87, 61, 95, 21, 62, 92, 73, 67, 9, 36, 64, 94, 33, 49, 49, 93, 44, 99, 14, 60, 30, 94, 39, 23, 96, 8, 29, 80, 40, 51, 92, 57, 98, 38, 10, 28, 20, 1, 11, 78, 25, 63, 31, 81, 50, 70, 71, 4, 43, 32, 37, 73, 84, 57, 8, 81, 92, 21, 79, 67, 72, 40, 46, 40, 40, 73, 38, 97, 15, 79, 47, 1, 99, 58, 100, 2, 16, 33, 16, 94, 83, 35, 41, 81, 7, 2, 2, 4, 65, 25, 87, 52, 62, 38, 38, 40, 78, 32, 49, 99, 18, 18, 53, 93, 54, 44, 25, 69, 99, 34, 85, 72, 24, 25, 66, 10, 41, 49, 65, 62, 95, 6, 48, 43, 50, 22, 17, 92, 92, 41, 95, 27, 48, 57, 37, 6, 49, 95, 18, 56, 100, 49, 61, 68, 16, 47, 16, 60, 85, 15, 4, 60, 89, 18, 82, 62, 83, 83, 39, 76, 98, 84, 97, 6, 5, 29, 72, 30, 71, 79, 50, 45, 84, 81, 58, 27, 20, 72, 34, 54, 93, 63, 36, 31, 41, 11, 62, 22, 69, 14, 18, 83, 19, 10, 32, 51, 57, 92, 77, 99, 21, 92, 66, 62, 89, 4, 86, 80, 4, 26, 77, 61, 84, 96, 50, 56, 91, 87, 68, 66, 39, 12, 60, 77, 31, 92, 61, 98]\n",
      "77 : 14\n",
      "36 : 9\n",
      "29 : 11\n",
      "20 : 9\n",
      "0 : 7\n",
      "86 : 9\n",
      "91 : 9\n",
      "32 : 15\n",
      "59 : 6\n",
      "32 : 15\n",
      "19 : 11\n",
      "53 : 11\n",
      "0 : 7\n",
      "99 : 10\n",
      "21 : 13\n",
      "94 : 13\n",
      "2 : 10\n",
      "53 : 11\n",
      "10 : 13\n",
      "92 : 17\n",
      "42 : 6\n",
      "8 : 14\n",
      "25 : 17\n",
      "26 : 16\n",
      "75 : 6\n",
      "69 : 8\n",
      "13 : 11\n",
      "60 : 13\n",
      "64 : 6\n",
      "25 : 17\n",
      "45 : 8\n",
      "19 : 11\n",
      "14 : 15\n",
      "58 : 11\n",
      "74 : 11\n",
      "23 : 11\n",
      "35 : 12\n",
      "28 : 9\n",
      "10 : 13\n",
      "83 : 13\n",
      "46 : 11\n",
      "83 : 13\n",
      "27 : 10\n",
      "8 : 14\n",
      "14 : 15\n",
      "14 : 15\n",
      "83 : 13\n",
      "48 : 7\n",
      "7 : 5\n",
      "4 : 13\n",
      "56 : 11\n",
      "73 : 12\n",
      "67 : 8\n",
      "89 : 11\n",
      "90 : 7\n",
      "3 : 8\n",
      "74 : 11\n",
      "63 : 8\n",
      "93 : 14\n",
      "87 : 10\n",
      "29 : 11\n",
      "2 : 10\n",
      "25 : 17\n",
      "26 : 16\n",
      "16 : 12\n",
      "96 : 10\n",
      "23 : 11\n",
      "9 : 5\n",
      "7 : 5\n",
      "60 : 13\n",
      "44 : 10\n",
      "4 : 13\n",
      "26 : 16\n",
      "1 : 12\n",
      "23 : 11\n",
      "51 : 10\n",
      "54 : 9\n",
      "97 : 7\n",
      "34 : 5\n",
      "96 : 10\n",
      "31 : 9\n",
      "77 : 14\n",
      "79 : 10\n",
      "10 : 13\n",
      "91 : 9\n",
      "96 : 10\n",
      "16 : 12\n",
      "57 : 12\n",
      "76 : 9\n",
      "11 : 5\n",
      "55 : 4\n",
      "17 : 11\n",
      "49 : 16\n",
      "74 : 11\n",
      "16 : 12\n",
      "32 : 15\n",
      "22 : 10\n",
      "66 : 13\n",
      "30 : 7\n",
      "60 : 13\n",
      "5 : 12\n",
      "91 : 9\n",
      "65 : 10\n",
      "21 : 13\n",
      "65 : 10\n",
      "35 : 12\n",
      "13 : 11\n",
      "54 : 9\n",
      "35 : 12\n",
      "66 : 13\n",
      "40 : 14\n",
      "97 : 7\n",
      "62 : 11\n",
      "8 : 14\n",
      "52 : 9\n",
      "51 : 10\n",
      "18 : 10\n",
      "1 : 12\n",
      "75 : 6\n",
      "61 : 16\n",
      "63 : 8\n",
      "53 : 11\n",
      "41 : 9\n",
      "66 : 13\n",
      "14 : 15\n",
      "43 : 7\n",
      "74 : 11\n",
      "87 : 10\n",
      "100 : 11\n",
      "84 : 12\n",
      "83 : 13\n",
      "33 : 10\n",
      "13 : 11\n",
      "58 : 11\n",
      "39 : 8\n",
      "14 : 15\n",
      "40 : 14\n",
      "35 : 12\n",
      "18 : 10\n",
      "56 : 11\n",
      "42 : 6\n",
      "71 : 12\n",
      "73 : 12\n",
      "13 : 11\n",
      "33 : 10\n",
      "56 : 11\n",
      "41 : 9\n",
      "9 : 5\n",
      "76 : 9\n",
      "44 : 10\n",
      "40 : 14\n",
      "86 : 9\n",
      "22 : 10\n",
      "8 : 14\n",
      "79 : 10\n",
      "40 : 14\n",
      "18 : 10\n",
      "26 : 16\n",
      "72 : 8\n",
      "14 : 15\n",
      "77 : 14\n",
      "71 : 12\n",
      "58 : 11\n",
      "67 : 8\n",
      "27 : 10\n",
      "17 : 11\n",
      "98 : 12\n",
      "17 : 11\n",
      "40 : 14\n",
      "14 : 15\n",
      "49 : 16\n",
      "71 : 12\n",
      "36 : 9\n",
      "19 : 11\n",
      "8 : 14\n",
      "77 : 14\n",
      "35 : 12\n",
      "17 : 11\n",
      "25 : 17\n",
      "46 : 11\n",
      "4 : 13\n",
      "47 : 13\n",
      "59 : 6\n",
      "82 : 7\n",
      "33 : 10\n",
      "5 : 12\n",
      "21 : 13\n",
      "20 : 9\n",
      "84 : 12\n",
      "5 : 12\n",
      "2 : 10\n",
      "58 : 11\n",
      "34 : 5\n",
      "21 : 13\n",
      "49 : 16\n",
      "45 : 8\n",
      "42 : 6\n",
      "12 : 8\n",
      "58 : 11\n",
      "54 : 9\n",
      "50 : 11\n",
      "76 : 9\n",
      "38 : 8\n",
      "0 : 7\n",
      "76 : 9\n",
      "5 : 12\n",
      "91 : 9\n",
      "42 : 6\n",
      "98 : 12\n",
      "9 : 5\n",
      "5 : 12\n",
      "55 : 4\n",
      "91 : 9\n",
      "99 : 10\n",
      "92 : 17\n",
      "62 : 11\n",
      "78 : 7\n",
      "66 : 13\n",
      "27 : 10\n",
      "79 : 10\n",
      "13 : 11\n",
      "63 : 8\n",
      "77 : 14\n",
      "5 : 12\n",
      "40 : 14\n",
      "25 : 17\n",
      "89 : 11\n",
      "21 : 13\n",
      "56 : 11\n",
      "5 : 12\n",
      "11 : 5\n",
      "68 : 4\n",
      "26 : 16\n",
      "14 : 15\n",
      "95 : 11\n",
      "100 : 11\n",
      "35 : 12\n",
      "83 : 13\n",
      "90 : 7\n",
      "3 : 8\n",
      "52 : 9\n",
      "53 : 11\n",
      "21 : 13\n",
      "94 : 13\n",
      "57 : 12\n",
      "14 : 15\n",
      "96 : 10\n",
      "20 : 9\n",
      "23 : 11\n",
      "20 : 9\n",
      "47 : 13\n",
      "49 : 16\n",
      "63 : 8\n",
      "87 : 10\n",
      "89 : 11\n",
      "88 : 6\n",
      "15 : 6\n",
      "59 : 6\n",
      "93 : 14\n",
      "94 : 13\n",
      "5 : 12\n",
      "70 : 11\n",
      "51 : 10\n",
      "93 : 14\n",
      "58 : 11\n",
      "90 : 7\n",
      "56 : 11\n",
      "81 : 10\n",
      "100 : 11\n",
      "65 : 10\n",
      "26 : 16\n",
      "81 : 10\n",
      "58 : 11\n",
      "90 : 7\n",
      "46 : 11\n",
      "17 : 11\n",
      "77 : 14\n",
      "47 : 13\n",
      "74 : 11\n",
      "1 : 12\n",
      "24 : 5\n",
      "36 : 9\n",
      "79 : 10\n",
      "50 : 11\n",
      "30 : 7\n",
      "92 : 17\n",
      "56 : 11\n",
      "27 : 10\n",
      "73 : 12\n",
      "17 : 11\n",
      "71 : 12\n",
      "41 : 9\n",
      "57 : 12\n",
      "21 : 13\n",
      "26 : 16\n",
      "43 : 7\n",
      "18 : 10\n",
      "30 : 7\n",
      "12 : 8\n",
      "19 : 11\n",
      "70 : 11\n",
      "74 : 11\n",
      "32 : 15\n",
      "82 : 7\n",
      "53 : 11\n",
      "37 : 7\n",
      "98 : 12\n",
      "45 : 8\n",
      "10 : 13\n",
      "67 : 8\n",
      "57 : 12\n",
      "95 : 11\n",
      "2 : 10\n",
      "89 : 11\n",
      "74 : 11\n",
      "61 : 16\n",
      "86 : 9\n",
      "73 : 12\n",
      "70 : 11\n",
      "35 : 12\n",
      "33 : 10\n",
      "1 : 12\n",
      "98 : 12\n",
      "25 : 17\n",
      "8 : 14\n",
      "83 : 13\n",
      "39 : 8\n",
      "37 : 7\n",
      "63 : 8\n",
      "43 : 7\n",
      "92 : 17\n",
      "10 : 13\n",
      "89 : 11\n",
      "88 : 6\n",
      "22 : 10\n",
      "56 : 11\n",
      "58 : 11\n",
      "32 : 15\n",
      "99 : 10\n",
      "49 : 16\n",
      "70 : 11\n",
      "26 : 16\n",
      "61 : 16\n",
      "4 : 13\n",
      "22 : 10\n",
      "53 : 11\n",
      "64 : 6\n",
      "25 : 17\n",
      "47 : 13\n",
      "62 : 11\n",
      "84 : 12\n",
      "90 : 7\n",
      "94 : 13\n",
      "88 : 6\n",
      "66 : 13\n",
      "35 : 12\n",
      "24 : 5\n",
      "3 : 8\n",
      "6 : 5\n",
      "57 : 12\n",
      "52 : 9\n",
      "77 : 14\n",
      "80 : 6\n",
      "14 : 15\n",
      "50 : 11\n",
      "66 : 13\n",
      "16 : 12\n",
      "54 : 9\n",
      "13 : 11\n",
      "19 : 11\n",
      "74 : 11\n",
      "80 : 6\n",
      "75 : 6\n",
      "12 : 8\n",
      "93 : 14\n",
      "5 : 12\n",
      "4 : 13\n",
      "20 : 9\n",
      "8 : 14\n",
      "98 : 12\n",
      "47 : 13\n",
      "47 : 13\n",
      "43 : 7\n",
      "87 : 10\n",
      "27 : 10\n",
      "10 : 13\n",
      "46 : 11\n",
      "67 : 8\n",
      "14 : 15\n",
      "39 : 8\n",
      "0 : 7\n",
      "78 : 7\n",
      "60 : 13\n",
      "80 : 6\n",
      "69 : 8\n",
      "95 : 11\n",
      "17 : 11\n",
      "26 : 16\n",
      "94 : 13\n",
      "93 : 14\n",
      "100 : 11\n",
      "51 : 10\n",
      "76 : 9\n",
      "33 : 10\n",
      "99 : 10\n",
      "44 : 10\n",
      "8 : 14\n",
      "85 : 9\n",
      "83 : 13\n",
      "15 : 6\n",
      "37 : 7\n",
      "80 : 6\n",
      "65 : 10\n",
      "25 : 17\n",
      "98 : 12\n",
      "22 : 10\n",
      "32 : 15\n",
      "60 : 13\n",
      "61 : 16\n",
      "51 : 10\n",
      "8 : 14\n",
      "55 : 4\n",
      "57 : 12\n",
      "32 : 15\n",
      "93 : 14\n",
      "53 : 11\n",
      "28 : 9\n",
      "73 : 12\n",
      "29 : 11\n",
      "22 : 10\n",
      "91 : 9\n",
      "74 : 11\n",
      "100 : 11\n",
      "44 : 10\n",
      "49 : 16\n",
      "25 : 17\n",
      "97 : 7\n",
      "48 : 7\n",
      "32 : 15\n",
      "32 : 15\n",
      "64 : 6\n",
      "82 : 7\n",
      "76 : 9\n",
      "85 : 9\n",
      "65 : 10\n",
      "27 : 10\n",
      "88 : 6\n",
      "30 : 7\n",
      "50 : 11\n",
      "98 : 12\n",
      "22 : 10\n",
      "19 : 11\n",
      "95 : 11\n",
      "23 : 11\n",
      "52 : 9\n",
      "45 : 8\n",
      "73 : 12\n",
      "86 : 9\n",
      "43 : 7\n",
      "1 : 12\n",
      "93 : 14\n",
      "64 : 6\n",
      "100 : 11\n",
      "19 : 11\n",
      "23 : 11\n",
      "22 : 10\n",
      "13 : 11\n",
      "32 : 15\n",
      "51 : 10\n",
      "51 : 10\n",
      "89 : 11\n",
      "21 : 13\n",
      "73 : 12\n",
      "8 : 14\n",
      "50 : 11\n",
      "26 : 16\n",
      "70 : 11\n",
      "16 : 12\n",
      "57 : 12\n",
      "98 : 12\n",
      "0 : 7\n",
      "96 : 10\n",
      "93 : 14\n",
      "81 : 10\n",
      "51 : 10\n",
      "49 : 16\n",
      "33 : 10\n",
      "3 : 8\n",
      "70 : 11\n",
      "88 : 6\n",
      "58 : 11\n",
      "93 : 14\n",
      "54 : 9\n",
      "29 : 11\n",
      "72 : 8\n",
      "15 : 6\n",
      "26 : 16\n",
      "72 : 8\n",
      "40 : 14\n",
      "85 : 9\n",
      "6 : 5\n",
      "34 : 5\n",
      "50 : 11\n",
      "97 : 7\n",
      "79 : 10\n",
      "61 : 16\n",
      "46 : 11\n",
      "62 : 11\n",
      "29 : 11\n",
      "96 : 10\n",
      "47 : 13\n",
      "66 : 13\n",
      "46 : 11\n",
      "60 : 13\n",
      "60 : 13\n",
      "75 : 6\n",
      "76 : 9\n",
      "39 : 8\n",
      "2 : 10\n",
      "71 : 12\n",
      "26 : 16\n",
      "86 : 9\n",
      "3 : 8\n",
      "57 : 12\n",
      "9 : 5\n",
      "92 : 17\n",
      "100 : 11\n",
      "82 : 7\n",
      "66 : 13\n",
      "86 : 9\n",
      "52 : 9\n",
      "32 : 15\n",
      "10 : 13\n",
      "47 : 13\n",
      "11 : 5\n",
      "69 : 8\n",
      "28 : 9\n",
      "94 : 13\n",
      "70 : 11\n",
      "61 : 16\n",
      "82 : 7\n",
      "29 : 11\n",
      "44 : 10\n",
      "8 : 14\n",
      "38 : 8\n",
      "94 : 13\n",
      "28 : 9\n",
      "61 : 16\n",
      "12 : 8\n",
      "29 : 11\n",
      "10 : 13\n",
      "33 : 10\n",
      "71 : 12\n",
      "81 : 10\n",
      "86 : 9\n",
      "84 : 12\n",
      "95 : 11\n",
      "1 : 12\n",
      "60 : 13\n",
      "81 : 10\n",
      "61 : 16\n",
      "97 : 7\n",
      "17 : 11\n",
      "20 : 9\n",
      "47 : 13\n",
      "78 : 7\n",
      "46 : 11\n",
      "76 : 9\n",
      "85 : 9\n",
      "94 : 13\n",
      "69 : 8\n",
      "18 : 10\n",
      "46 : 11\n",
      "23 : 11\n",
      "31 : 9\n",
      "79 : 10\n",
      "46 : 11\n",
      "24 : 5\n",
      "40 : 14\n",
      "2 : 10\n",
      "60 : 13\n",
      "77 : 14\n",
      "56 : 11\n",
      "66 : 13\n",
      "25 : 17\n",
      "3 : 8\n",
      "13 : 11\n",
      "70 : 11\n",
      "36 : 9\n",
      "59 : 6\n",
      "8 : 14\n",
      "26 : 16\n",
      "81 : 10\n",
      "73 : 12\n",
      "23 : 11\n",
      "95 : 11\n",
      "4 : 13\n",
      "46 : 11\n",
      "35 : 12\n",
      "23 : 11\n",
      "71 : 12\n",
      "71 : 12\n",
      "47 : 13\n",
      "53 : 11\n",
      "14 : 15\n",
      "3 : 8\n",
      "5 : 12\n",
      "45 : 8\n",
      "93 : 14\n",
      "50 : 11\n",
      "48 : 7\n",
      "96 : 10\n",
      "85 : 9\n",
      "37 : 7\n",
      "63 : 8\n",
      "40 : 14\n",
      "54 : 9\n",
      "96 : 10\n",
      "36 : 9\n",
      "16 : 12\n",
      "94 : 13\n",
      "67 : 8\n",
      "72 : 8\n",
      "92 : 17\n",
      "52 : 9\n",
      "89 : 11\n",
      "19 : 11\n",
      "86 : 9\n",
      "41 : 9\n",
      "10 : 13\n",
      "73 : 12\n",
      "65 : 10\n",
      "65 : 10\n",
      "13 : 11\n",
      "26 : 16\n",
      "29 : 11\n",
      "20 : 9\n",
      "74 : 11\n",
      "17 : 11\n",
      "1 : 12\n",
      "79 : 10\n",
      "45 : 8\n",
      "19 : 11\n",
      "49 : 16\n",
      "19 : 11\n",
      "1 : 12\n",
      "49 : 16\n",
      "28 : 9\n",
      "31 : 9\n",
      "71 : 12\n",
      "83 : 13\n",
      "37 : 7\n",
      "87 : 10\n",
      "41 : 9\n",
      "61 : 16\n",
      "61 : 16\n",
      "70 : 11\n",
      "77 : 14\n",
      "28 : 9\n",
      "90 : 7\n",
      "53 : 11\n",
      "87 : 10\n",
      "44 : 10\n",
      "45 : 8\n",
      "84 : 12\n",
      "26 : 16\n",
      "13 : 11\n",
      "27 : 10\n",
      "23 : 11\n",
      "82 : 7\n",
      "36 : 9\n",
      "25 : 17\n",
      "59 : 6\n",
      "44 : 10\n",
      "85 : 9\n",
      "15 : 6\n",
      "42 : 6\n",
      "55 : 4\n",
      "88 : 6\n",
      "28 : 9\n",
      "92 : 17\n",
      "10 : 13\n",
      "1 : 12\n",
      "91 : 9\n",
      "56 : 11\n",
      "94 : 13\n",
      "84 : 12\n",
      "75 : 6\n",
      "24 : 5\n",
      "71 : 12\n",
      "87 : 10\n",
      "35 : 12\n",
      "78 : 7\n",
      "27 : 10\n",
      "68 : 4\n",
      "31 : 9\n",
      "65 : 10\n",
      "31 : 9\n",
      "85 : 9\n",
      "48 : 7\n",
      "3 : 8\n",
      "44 : 10\n",
      "100 : 11\n",
      "12 : 8\n",
      "74 : 11\n",
      "83 : 13\n",
      "64 : 6\n",
      "29 : 11\n",
      "33 : 10\n",
      "25 : 17\n",
      "28 : 9\n",
      "38 : 8\n",
      "84 : 12\n",
      "49 : 16\n",
      "61 : 16\n",
      "66 : 13\n",
      "4 : 13\n",
      "1 : 12\n",
      "75 : 6\n",
      "4 : 13\n",
      "52 : 9\n",
      "59 : 6\n",
      "21 : 13\n",
      "31 : 9\n",
      "95 : 11\n",
      "69 : 8\n",
      "89 : 11\n",
      "12 : 8\n",
      "78 : 7\n",
      "7 : 5\n",
      "77 : 14\n",
      "0 : 7\n",
      "16 : 12\n",
      "98 : 12\n",
      "36 : 9\n",
      "70 : 11\n",
      "67 : 8\n",
      "89 : 11\n",
      "42 : 6\n",
      "92 : 17\n",
      "14 : 15\n",
      "12 : 8\n",
      "84 : 12\n",
      "5 : 12\n",
      "91 : 9\n",
      "16 : 12\n",
      "52 : 9\n",
      "100 : 11\n",
      "62 : 11\n",
      "92 : 17\n",
      "13 : 11\n",
      "32 : 15\n",
      "35 : 12\n",
      "39 : 8\n",
      "2 : 10\n",
      "25 : 17\n",
      "30 : 7\n",
      "7 : 5\n",
      "90 : 7\n",
      "0 : 7\n",
      "99 : 10\n",
      "61 : 16\n",
      "53 : 11\n",
      "38 : 8\n",
      "77 : 14\n",
      "54 : 9\n",
      "47 : 13\n",
      "48 : 7\n",
      "93 : 14\n",
      "69 : 8\n",
      "17 : 11\n",
      "21 : 13\n",
      "87 : 10\n",
      "61 : 16\n",
      "95 : 11\n",
      "21 : 13\n",
      "62 : 11\n",
      "92 : 17\n",
      "73 : 12\n",
      "67 : 8\n",
      "9 : 5\n",
      "36 : 9\n",
      "64 : 6\n",
      "94 : 13\n",
      "33 : 10\n",
      "49 : 16\n",
      "49 : 16\n",
      "93 : 14\n",
      "44 : 10\n",
      "99 : 10\n",
      "14 : 15\n",
      "60 : 13\n",
      "30 : 7\n",
      "94 : 13\n",
      "39 : 8\n",
      "23 : 11\n",
      "96 : 10\n",
      "8 : 14\n",
      "29 : 11\n",
      "80 : 6\n",
      "40 : 14\n",
      "51 : 10\n",
      "92 : 17\n",
      "57 : 12\n",
      "98 : 12\n",
      "38 : 8\n",
      "10 : 13\n",
      "28 : 9\n",
      "20 : 9\n",
      "1 : 12\n",
      "11 : 5\n",
      "78 : 7\n",
      "25 : 17\n",
      "63 : 8\n",
      "31 : 9\n",
      "81 : 10\n",
      "50 : 11\n",
      "70 : 11\n",
      "71 : 12\n",
      "4 : 13\n",
      "43 : 7\n",
      "32 : 15\n",
      "37 : 7\n",
      "73 : 12\n",
      "84 : 12\n",
      "57 : 12\n",
      "8 : 14\n",
      "81 : 10\n",
      "92 : 17\n",
      "21 : 13\n",
      "79 : 10\n",
      "67 : 8\n",
      "72 : 8\n",
      "40 : 14\n",
      "46 : 11\n",
      "40 : 14\n",
      "40 : 14\n",
      "73 : 12\n",
      "38 : 8\n",
      "97 : 7\n",
      "15 : 6\n",
      "79 : 10\n",
      "47 : 13\n",
      "1 : 12\n",
      "99 : 10\n",
      "58 : 11\n",
      "100 : 11\n",
      "2 : 10\n",
      "16 : 12\n",
      "33 : 10\n",
      "16 : 12\n",
      "94 : 13\n",
      "83 : 13\n",
      "35 : 12\n",
      "41 : 9\n",
      "81 : 10\n",
      "7 : 5\n",
      "2 : 10\n",
      "2 : 10\n",
      "4 : 13\n",
      "65 : 10\n",
      "25 : 17\n",
      "87 : 10\n",
      "52 : 9\n",
      "62 : 11\n",
      "38 : 8\n",
      "38 : 8\n",
      "40 : 14\n",
      "78 : 7\n",
      "32 : 15\n",
      "49 : 16\n",
      "99 : 10\n",
      "18 : 10\n",
      "18 : 10\n",
      "53 : 11\n",
      "93 : 14\n",
      "54 : 9\n",
      "44 : 10\n",
      "25 : 17\n",
      "69 : 8\n",
      "99 : 10\n",
      "34 : 5\n",
      "85 : 9\n",
      "72 : 8\n",
      "24 : 5\n",
      "25 : 17\n",
      "66 : 13\n",
      "10 : 13\n",
      "41 : 9\n",
      "49 : 16\n",
      "65 : 10\n",
      "62 : 11\n",
      "95 : 11\n",
      "6 : 5\n",
      "48 : 7\n",
      "43 : 7\n",
      "50 : 11\n",
      "22 : 10\n",
      "17 : 11\n",
      "92 : 17\n",
      "92 : 17\n",
      "41 : 9\n",
      "95 : 11\n",
      "27 : 10\n",
      "48 : 7\n",
      "57 : 12\n",
      "37 : 7\n",
      "6 : 5\n",
      "49 : 16\n",
      "95 : 11\n",
      "18 : 10\n",
      "56 : 11\n",
      "100 : 11\n",
      "49 : 16\n",
      "61 : 16\n",
      "68 : 4\n",
      "16 : 12\n",
      "47 : 13\n",
      "16 : 12\n",
      "60 : 13\n",
      "85 : 9\n",
      "15 : 6\n",
      "4 : 13\n",
      "60 : 13\n",
      "89 : 11\n",
      "18 : 10\n",
      "82 : 7\n",
      "62 : 11\n",
      "83 : 13\n",
      "83 : 13\n",
      "39 : 8\n",
      "76 : 9\n",
      "98 : 12\n",
      "84 : 12\n",
      "97 : 7\n",
      "6 : 5\n",
      "5 : 12\n",
      "29 : 11\n",
      "72 : 8\n",
      "30 : 7\n",
      "71 : 12\n",
      "79 : 10\n",
      "50 : 11\n",
      "45 : 8\n",
      "84 : 12\n",
      "81 : 10\n",
      "58 : 11\n",
      "27 : 10\n",
      "20 : 9\n",
      "72 : 8\n",
      "34 : 5\n",
      "54 : 9\n",
      "93 : 14\n",
      "63 : 8\n",
      "36 : 9\n",
      "31 : 9\n",
      "41 : 9\n",
      "11 : 5\n",
      "62 : 11\n",
      "22 : 10\n",
      "69 : 8\n",
      "14 : 15\n",
      "18 : 10\n",
      "83 : 13\n",
      "19 : 11\n",
      "10 : 13\n",
      "32 : 15\n",
      "51 : 10\n",
      "57 : 12\n",
      "92 : 17\n",
      "77 : 14\n",
      "99 : 10\n",
      "21 : 13\n",
      "92 : 17\n",
      "66 : 13\n",
      "62 : 11\n",
      "89 : 11\n",
      "4 : 13\n",
      "86 : 9\n",
      "80 : 6\n",
      "4 : 13\n",
      "26 : 16\n",
      "77 : 14\n",
      "61 : 16\n",
      "84 : 12\n",
      "96 : 10\n",
      "50 : 11\n",
      "56 : 11\n",
      "91 : 9\n",
      "87 : 10\n",
      "68 : 4\n",
      "66 : 13\n",
      "39 : 8\n",
      "12 : 8\n",
      "60 : 13\n",
      "77 : 14\n",
      "31 : 9\n",
      "92 : 17\n",
      "61 : 16\n",
      "98 : 12\n"
     ]
    }
   ],
   "source": [
    "#答案：15.\n",
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入下标上限2\n",
      "输入下标下限10\n",
      "输入一个列表[li,yu,shi,5,9,7]\n",
      "['li', 'yu', 'shi', '5', '9', '7']\n",
      "['shi', '5', '9', '7']\n"
     ]
    }
   ],
   "source": [
    "#答案： 16.\n",
    "x = int(input(\"输入下标上限\"))\n",
    "y = int(input(\"输入下标下限\"))\n",
    "z = input(\"输入一个列表\")\n",
    "c=z[1:-1].split(\",\")\n",
    "print(c)\n",
    "print(c[x:y+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input your thingliyushi\n",
      "您输入的键不存在\n"
     ]
    }
   ],
   "source": [
    "#答案： 17.\n",
    "d = {'li':5,'yu':9,'shi':7}\n",
    "a = input('input your thing')\n",
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 6, 7, 18, 35, 38, 40, 45, 76, 92, 100, 94, 84, 66, 66, 58, 31, 26, 17, 5]\n"
     ]
    }
   ],
   "source": [
    "#答案： 18.\n",
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
